import unittest
from queues.array_deque import ArrayDeque

class TestArrayDeque(unittest.TestCase):
    def test_push_full_capacity(self):
        deque = ArrayDeque(3)
        deque.push_last(1)
        deque.push_last(2)
        deque.push_last(3)
        with self.assertLogs() as cm:
            deque.push_first(4)
        self.assertIn('双向队列已满', cm.output[0])

    def test_empty_pop_exceptions(self):
        deque = ArrayDeque(5)
        with self.assertRaises(IndexError):
            deque.pop_first()
        with self.assertRaises(IndexError):
            deque.pop_last()

    def test_mixed_operations(self):
        deque = ArrayDeque(5)
        deque.push_first(2)
        deque.push_last(3)
        deque.push_first(1)
        self.assertEqual(deque.peek_first(), 1)
        self.assertEqual(deque.peek_last(), 3)
        self.assertEqual(deque.pop_first(), 1)
        self.assertEqual(deque.pop_last(), 3)

    def test_index_wrapping(self):
        deque = ArrayDeque(3)
        deque.push_last(1)
        deque.push_last(2)
        deque.pop_first()
        deque.push_last(3)
        self.assertEqual(deque.to_list(), [2, 3])

    def test_expansion_after_capacity(self):
        deque = ArrayDeque(2)
        deque.push_last(1)
        deque.push_last(2)
        deque.pop_first()
        deque.push_last(3)
        self.assertEqual(deque.to_list(), [2, 3])

if __name__ == '__main__':
    unittest.main()
